package cn.declare.controller.logistics;

import cn.declare.service.logistics.LogisticsService;
import cn.declare.vo.talent.LogisticsoptionVo;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/log")
@Slf4j
public class LogisticsController {

    @Resource
    private LogisticsService logisticsService;

    @GetMapping("/findall/{logisticsoption}")
    public String getFindAll(@PathVariable("logisticsoption") Integer logisticsoption){
        LogisticsoptionVo logisticsoptionVo = logisticsService.selectAll(logisticsoption);
        return JSON.toJSONString(logisticsoptionVo);
    }

    @PostMapping("/logAdd")
    public int getLogAdd(@RequestBody LogisticsoptionVo logisticsoptionVo){
        int logAdd = logisticsService.getLogAdd(logisticsoptionVo);
        return logAdd;
    }

    @GetMapping("/logSelect")
    public List<LogisticsoptionVo> getFindAll(){
        List<LogisticsoptionVo> findAll = logisticsService.getFindAll();
        return findAll;
    }

    @GetMapping("/approv/{id}")
    public LogisticsoptionVo getFindByID(@PathVariable("id")Integer id){
        LogisticsoptionVo findById = logisticsService.getFindById(id);
        return findById;
    }

    @PutMapping("/update")
    public int UpdateLog(@RequestBody LogisticsoptionVo logisticsoptionVo){
        int update = logisticsService.getUpdate(logisticsoptionVo);
        return update;
    }

    @GetMapping("/date")
    public List<LogisticsoptionVo> getDate(@Param("startDate") String startDate,
                                      @Param("lastDate")  String lastDate) throws ParseException {
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = dateFormat1.parse(startDate);
        Date parse1 = dateFormat1.parse(lastDate);
        log.info("时间为：{}",startDate);
        log.info("时间为：{}",lastDate);
        List<LogisticsoptionVo> findByCreatDate = logisticsService.getFindByCreatDate(parse, parse1);
        return findByCreatDate;
    }
}
